package logic

import (
	"context"
	"fmt"

	"MBTI/rpc/admin/adm"
	"MBTI/rpc/admin/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type SearchStuByStuNoLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewSearchStuByStuNoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SearchStuByStuNoLogic {
	return &SearchStuByStuNoLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *SearchStuByStuNoLogic) SearchStuByStuNo(in *adm.SearchStuByStuNoReq) (*adm.SearchResp, error) {
	// todo: add your logic here and delete this line
	fmt.Println("开查")
	_search, _total, err := l.svcCtx.ResultModel.SearchResultByStuNo(in.StudentNo)
	fmt.Println("用学号查完了")
	fmt.Println(err)
	if err != nil {
		return nil, err
	}

	searchHandle := make([]*adm.Search, 0)
	for _, e := range _search {
		searchHandle = append(searchHandle, &adm.Search{
			StudentNo:   e.StudentNo,
			StudentName: e.Student.StudentName,
			AcademyName: e.Student.AcademyName,
			ClassName:   e.Student.ClassName,
			ClassNo:     e.Student.ClassNo,
			CreateAt:    e.CreatedAt.String(),
			MBTI:        e.MBTI,
			Answer:      e.Answer,
		})

	}
	return &adm.SearchResp{Total: _total, Searchresp: searchHandle}, nil
}
